package com.rz.paas.test.SettingDetail;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.rz.paas.baselib.recyclerView.CommonAdapter;
import com.rz.paas.baselib.recyclerView.CommonHolder;
import com.rz.paas.test.R;

public class SettingDetailAdapter extends CommonAdapter<TypeData> {
    public SettingDetailAdapter(Context context) {
        super(context, R.layout.type_item);
    }

    @Override
    protected void bindData(CommonHolder holder, TypeData data, int position) {
        holder.setText(R.id.item_name, data.getName());
        if (data.isSelected()) {
            holder.setVisible(R.id.selected_icon, View.VISIBLE);
        } else {
            holder.setVisible(R.id.selected_icon, View.INVISIBLE);
        }

        if (isItemFooter(position)) {
            holder.setVisible(R.id.split_line, View.INVISIBLE);
        } else {
            holder.setVisible(R.id.split_line, View.VISIBLE);
        }
    }

    public boolean isItemHeader(int position) {
        if (position == 0) {
            return true;
        } else {
            String resolutionLast = getData().get(position - 1).getGroupName();


            String resolutionCurrent = getData().get(position).getGroupName();

            if (resolutionLast.equals(resolutionCurrent)) {
                return false;
            } else {
                return true;
            }

        }
    }

    public boolean isItemFooter(int position) {


        String resolutionCurrent = getData().get(position).getGroupName();
        if (TextUtils.isEmpty(resolutionCurrent)) return position + 1 >= getData().size();
        if (position + 1 >= getData().size()) return true;
        String resolutionNext = getData().get(position + 1).getGroupName();
        return !resolutionCurrent.equals(resolutionNext);
    }

}